<?php

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {
        $this->call('RolePermissionSeeder');
        $this->call('OptionSeeder');
        $this->call('ClassesSeeder');
        $this->call('UserSeeder');

        Cache::flush();

        if (!is_dir(public_path() . "/Temp")) {
            mkdir(public_path() . "/Temp", 0777);
        }

        if (!is_dir(public_path() . "/profile-image")) {
            mkdir(public_path() . "/profile-image", 0777);
        }

        $this->command->info('User table seeded!');
    }

}

class RolePermissionSeeder extends Seeder {

    public function run() {
        DB::table('roles')->truncate();
        DB::table('permissions')->truncate();
        DB::table('permission_role')->truncate();
        DB::table('assigned_roles')->truncate();

        // <editor-fold defaultstate="collapsed" desc="Roles Permissions">
        DB::insert(
            "INSERT INTO `roles` (`type`, `name`, `updater`, `created_at`, `updated_at`) VALUES
            ('GROUP', 'Quản Trị', 'admin', '2014-04-22 09:02:34', '2014-04-22 09:02:34');"
        );

        DB::insert(
            "INSERT INTO `permissions` (`name`, `display_name`, `updater`, `created_at`, `updated_at`) VALUES
            ('manage-User', 'Quản Lý Tài Khoản', 'admin', '2014-04-22 02:03:24', '2014-04-22 02:03:24'),
            ('manage-Class', 'Quản Lý Lớp Học', 'admin', '2014-04-24 03:37:12', '2014-04-24 03:37:12'),
            ('manage-User-Create', 'Tạo Tài Khoản', 'admin', '2014-04-24 03:39:56', '2014-04-24 03:39:56'),
            ('manage-User-Attendance', 'Điểm Danh', 'admin', '2014-04-24 03:48:04', '2014-04-24 03:51:25'),
            ('manage-User-Attendance-Score', 'Ghi Điểm', 'admin', '2014-04-24 03:48:56', '2014-04-24 03:52:38'),
            ('manage-User-Review', 'Đánh Giá Cuối Năm', 'admin', '2014-04-24 03:49:33', '2014-04-24 03:52:02'),
            ('manage-Document', 'Quản Lý Tài Liệu', 'admin', '2014-04-24 03:49:33', '2014-04-24 03:52:02'),
            ('permission', 'Phân Quyền', 'admin', '2014-04-24 03:50:08', '2014-04-24 03:50:08'),
            ('system-option', 'Thông Số Hệ Thống', 'admin', '2014-04-24 03:50:34', '2014-04-24 03:50:34');"
        );
        // </editor-fold>
    }

}

class OptionSeeder extends Seeder {

    public function run() {
        DB::table('options')->truncate();

        // <editor-fold defaultstate="collapsed" desc="Options">
        DB::insert(
            "INSERT INTO `options` (`type`, `key`, `data`) VALUES
            ('COURSE', '2013', '{\"start\":\"2013-07-01\",\"end\":\"2014-06-30\"}'),
            ('COURSE', '2014', '{\"start\":\"2014-07-01\",\"end\":\"2015-06-30\"}'),
            ('COURSE', '2015', '{\"start\":\"2015-07-01\",\"end\":\"2016-06-30\"}'),
            ('LE', 'T', '{\"name\":\"Trắng\",\"minus\":\"-0.3\"}'),
            ('LE', 'P', '{\"name\":\"Vắng Có Phép\",\"minus\":-0.2}'),
            ('LE', 'H', '{\"name\":\"Hồng\",\"minus\":\"-0.2\"}'),
            ('LE', 'K', '{\"name\":\"Vắng Không Phép\",\"minus\":\"-0.5\"}'),
            ('HOC', 'K', '{\"name\":\"Vắng Không Phép\",\"minus\":-0.5}'),
            ('HOC', 'P', '{\"name\":\"Vắng Có Phép\",\"minus\":\"-0.2\"}'),
            ('NGANH', 'AU_NHI', 'Ấu Nhi'),
            ('NGANH', 'THIEU_NHI', 'Thiếu Nhi'),
            ('NGANH', 'NGHIA_SI', 'Nghĩa Sĩ'),
            ('NGANH', 'HUYNH_TRUONG_DU_BI', 'Huynh Trưởng Dự Bị'),
            ('CAP', 'CHIEN_CON', 'Chiên Con'),
            ('CAP', '1', '1'),
            ('CAP', '2', '2'),
            ('CAP', '3', '3'),
            ('CAP', '4', '4'),
            ('CAP', '5', '5'),
            ('CAP', '6', '6'),
            ('DOI', '1', '1'),
            ('DOI', '2', '2'),
            ('DOI', '3', '3'),
            ('DOI', '4', '4'),
            ('USERCREW', 'BHT', 'Ban Học Tập'),
            ('USERCREW', 'BSH', 'Ban Sinh Hoạt'),
            ('USERCREW', 'BPV', 'Ban Phụng Vụ'),
            ('USERCREW', 'BTT', 'Ban Thông Tin'),
            ('USERCREW', 'BDH', 'Ban Điều Hành'),
            ('USERTYPE', 'THIEU_NHI', 'Thiếu Nhi'),
            ('USERTYPE', 'HUYNH_TRUONG', 'Huynh Trưởng'),
            ('RANK', 'HANG_I', 'Hạng 1'),
            ('RANK', 'HANG_II', 'Hạng 2'),
            ('RANK', 'HANG_III', 'Hạng 3'),
            ('RANK', 'KHUYEN_KHICH', 'Khuyến Khích'),
            ('RANK', 'LEN_LOP', 'Lên Lớp'),
            ('RANK', 'O_LAI', 'Ở Lại Lớp'),
            ('RELATIONSHIP', 'CHA', 'Cha'),
            ('RELATIONSHIP', 'ME', 'Mẹ'),
            ('RELATIONSHIP', 'ONG_BA', 'Ông/Bà'),
            ('RELATIONSHIP', 'CO_CHU', 'Cô/Chú'),
            ('RELATIONSHIP', 'OTHER', 'Trường Hợp Khác'),
            ('LAN_KIEM_TRA', 'LAN_1', 'Lần 1'),
            ('LAN_KIEM_TRA', 'LAN_2', 'Lần 2'),
            ('DOT_KIEM_TRA', 'DOT_1', 'Đợt 1'),
            ('DOT_KIEM_TRA', 'DOT_2', 'Đợt 2'),
            ('DOT_KIEM_TRA', 'DOT_3', 'Đợt 3'),
            ('DOT_KIEM_TRA', 'DOT_4', 'Đợt 4'),
            ('DOT_KIEM_TRA', 'DOT_5', 'Đợt 5'),
            ('DOT_KIEM_TRA', 'DOT_6', 'Đợt 6');"
        );
        // </editor-fold>
    }

}

class ClassesSeeder extends Seeder {

    public function run() {
        DB::table('classes')->truncate();

        // <editor-fold defaultstate="collapsed" desc="Classes">
        DB::table('classes')->insert(array(
            array(
                "course" => 2013,
                "team"   => 'AU_NHI',
                "level"  => 'CHIEN_CON',
                "crew"   => 0,
            ),
            array(
                "course" => 2013,
                "team"   => 'AU_NHI',
                "level"  => 1,
                "crew"   => 1,
            ),
            array(
                "course" => 2013,
                "team"   => 'AU_NHI',
                "level"  => 1,
                "crew"   => 2,
            ),
        ));
        // </editor-fold>
    }

}

class UserSeeder extends Seeder {

    public function run() {

        DB::table('user')->truncate();
        DB::table('user_class')->truncate();
        DB::table('user_score')->truncate();
        DB::table('user_score_log')->truncate();
        DB::table('user_dear')->truncate();

        $faker = Faker\Factory::create();

        // <editor-fold defaultstate="collapsed" desc="User">
        for ($i = 13000; $i < 13101; $i++) {

            if ($i == 13000) {
                DB::table('user')->insert(array(
                    array(
                        //Admin
                        "id"                => 'admin',
                        "passwd"            => Hash::make('1'),
                        "usertype"          => "HUYNH_TRUONG",
                        "userstatus"        => "",
                        "saint"             => "Giuse",
                        "username"          => "Hồ Minh Long",
                        "firstname"         => "Long",
                        "gender"            => "1",
                        "birthday"          => "1988-07-09",
                        "usercrew"          => "",
                        "baptism_date"      => "",
                        "eucharist_date"    => "",
                        "confirmation_date" => "",
                        "email"             => "hominhlong.it@gmail.com",
                        "phone"             => "",
                        "address"           => "",
                        "parish"            => "",
                        "gencode"           => "",
                        "note"              => "",
                        "updater"           => "",
                        "created_at"        => date('Y-m-d H:i:s'),
                        "updated_at"        => date('Y-m-d H:i:s'),
                    )
                ));
            } else {
                DB::table('user')->insert(array(
                    array(
                        "id"                => $i,
                        "passwd"            => Hash::make('1'),
                        "usertype"          => "THIEU_NHI",
                        "userstatus"        => "",
                        "saint"             => $faker->firstname,
                        "username"          => $faker->name,
                        "firstname"         => $faker->firstname,
                        "gender"            => "1",
                        "birthday"          => $faker->datetime,
                        "usercrew"          => "",
                        "baptism_date"      => $faker->datetime,
                        "eucharist_date"    => $faker->datetime,
                        "confirmation_date" => $faker->datetime,
                        "email"             => $faker->companyEmail,
                        "phone"             => $faker->phoneNumber,
                        "address"           => $faker->address,
                        "parish"            => "",
                        "gencode"           => "",
                        "note"              => "",
                        "updater"           => "",
                        "created_at"        => date('Y-m-d H:i:s'),
                        "updated_at"        => date('Y-m-d H:i:s'),
                    )
                ));
            }
        }
        //</editor-fold>
    }

}
